import requests

class ApiBase:
    def __init__(self):
        self.url = 'http://10.59.9.12:7001'
        self.session = requests.session()
        # 设置默认请求头（可被后续请求的 headers 参数覆盖）
        self.session.headers.update({
            'Content-Type': 'application/json',
        })

    def request(self, method, path,** kwargs):
        """通用请求方法，通过 **kwargs 接收所有请求参数"""
        url = f"{self.url}{path}"
        print(f"\n发送{method}请求: {url}")
        # 支持所有 requests 支持的参数（如 timeout、cookies、headers 等）
        response = self.session.request(method, url, **kwargs)
        print(f"响应状态码: {response.status_code}")
        return response

    def get(self, path,** kwargs):
        """GET请求：支持所有扩展参数"""
        return self.request("GET", path, **kwargs)

    def post(self, path,** kwargs):
        """POST请求：支持json/data/headers等参数"""
        return self.request("POST", path, **kwargs)

    def put(self, path,** kwargs):
        """PUT请求：支持扩展参数"""
        return self.request("PUT", path, **kwargs)

    def delete(self, path,** kwargs):
        """DELETE请求：支持扩展参数"""
        return self.request("DELETE", path, **kwargs)